package com.dynamoc.jdk;

import com.dynamoc.aspect.LogForService;

import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;

import java.lang.reflect.Method;

public class JdkDybnamic {
    public Object getProxyObject(Object tagetClass){
        Object o = Proxy.newProxyInstance(tagetClass.getClass().getClassLoader(), tagetClass.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                LogForService logForService = new LogForService();
                logForService.beforeStrengthen();
                Object invoke = method.invoke(tagetClass, objects);
                logForService.afterStrengthen();
                return invoke;
            }
        });
        return o;
    }
}
